<?php
/**
 *
 * @author james
 * @version 
 */
require_once 'Zend/Loader/PluginLoader.php';
require_once 'Zend/Controller/Action/Helper/Abstract.php';

/**
 * Activity Action Helper 
 * 
 * @uses actionHelper Zend_Controller_Action_Helper
 */
class Zend_Controller_Action_Helper_Activity extends Zend_Controller_Action_Helper_Abstract {
	/**
	 * @var Zend_Loader_PluginLoader
	 */
	public $pluginLoader;
	
	/**
	 * Constructor: initialize plugin loader
	 * 
	 * @return void
	 */
	public function __construct() {
		// TODO Auto-generated Constructor
		$this->pluginLoader = new Zend_Loader_PluginLoader ( );
	}
	
	/**
	 * Strategy pattern: call helper as broker method
	 */
	public function direct($activities) {
		$ret = array();
		$index = 0;
		$user = new User();
		$userBook = new UserBook();
		foreach ($activities as $activity) {
			$activityDTO = new ActivityDTO();
			$activityDTO->user = Activity::getUser($activity);
			$activityDTO->type = $activity->type;
			$type = $activity->type;
			$userHelper = $this->_actionController->getHelper("user");
			switch($type) {
				case Activity::ACTIVATE_USER:
					$activityDTO->user = $user->findById($activity->object);
					$activityDTO->presentUsername = $userHelper->getUserPresentName($activityDTO->user);
					$activityDTO->date = $activity->created;//$userHelper->getActivateDate($activityDTO->user);
					break;
				case Activity::USER_ADD_BOOK:
					$activityDTO->presentUsername = $userHelper->getUserPresentName($activityDTO->user);
					$activityDTO->userBook = $userBook->findById($activity->object);
					$activityDTO->book = UserBook::getBook($activityDTO->userBook);
					$activityDTO->date = $activity->created;
					break;
			}
			$ret[$index++] = $activityDTO;
		}
		return $ret;
	}
}

